package com.lwh.springboot.controller;

import com.lwh.springboot.pojo.entity.Car;
import com.lwh.springboot.service.ICarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/car")
public class CarController {
    @Autowired
    private ICarService carService;

    @RequestMapping("/selectAll")
    public String selectAll(Model model) {
        System.out.println("CarController.selectAll");
        List<Car> list = carService.selectAll();

        model.addAttribute("list", list);
        return "index";
    }

    @RequestMapping("/toCarDetail")
    public String toCarDetail(Integer id, Model model) {
        Car car = carService.selectById(id);
        model.addAttribute("car", car);
        return "car_detail";
    }

}
